<template>
	<view class="page">
		<swiper class="goods-swiper" :indicator-dots="true"  :autoplay="true" :interval="3000" :circular="true">
			<swiper-item v-for="banner in goodsInfo.headimg" :key="banner.id">
				<view class="home1-img-box">
					<image :src="banner.url" mode="widthFix" class="home1-img"></image>
				</view>
			</swiper-item>
		</swiper>
		<view class="row1">
			<view class="price">
				<view class="price-left">
					<view class="price-icon">￥</view>
					<view class="sale-price">{{salf_price}}</view>
					<view class="market-price" v-if="market_price != 0">￥{{market_price}}</view>
				</view>
				<view style="color: #999;">
					<view>已售{{goodsInfo.salf_num}}</view>
				</view>
			</view>
			<view class="money">
				<view class="money-item">
					<text class="money-left" v-if="coupon != 0">券：￥{{coupon}}</text>
					<text class="money-right" v-if="money != 0">赠送奉献值</text>
				</view>
			</view>
			<view class="slaf-num" style="font-size: 32rpx;line-height: 1.5;margin-top: 20rpx;color: #111;font-weight: 600;">{{goodsInfo.title}}</view>
		</view>
		<view class="content" style="">
			<view class="title" style="">商品详情</view>
			<view>
				<view class="desc" v-for="(item,index) in goodsInfo.desc">
					<img :src="item" alt="" class="content-img">
				</view>
			</view>
			
		</view>
		<view class="footer">
			<view class="footer1">
				<view @tap="goLink('/pages/home/index',1)">
					<img src="@/static/icons/home.png" class="footer-img" />
					<view class="footer-name">首页</view>
				</view>
				<view style="margin-left: 40rpx;" @tap="tel()">
					<img src="@/static/icons/kefu.png" class="footer-img" />
					<view class="footer-name">客服</view>
				</view>
				<view style="margin-left: 40rpx;" @tap="goLink('/pages/my/orders',2)">
					<img src="@/static/icons/order.png" class="footer-img" />
					<view class="footer-name">订单</view>
				</view>
			</view>
			<view class="link" @tap="link()">
				<view class="link-title">立即下单</view>
				<view class="link-price" v-if="buy_money  != 0">购买省￥{{buy_money}}</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import api from "@/api/";
	import shop from "@/api/shop";
	export default {
		data() {
			return {
				goodsInfo:{
					headimg:[],
					title:'品',
					salf_num:0,
					shop_name:'',
					desc_imgs:[],
					desc:'',
				},
				price:0,
				market_price:0,
				coupon:0,
				money:0,
				buy_money:0,
				type:1,
				goodsId:0
			}
		},
		onLoad(e) {
			console.log(e)
			this.type = e.type
			this.goodsId = e.goodsId
			this.price = e.price
			this.market_price = e.market_price
			this.salf_price = e.salf_price
			this.money = e.money
			this.coupon = e.coupon
			this.buy_money = e.buy_money
			this.getGoodsInfo()
		},
		methods: {
			goLink(url,type){
				if(type ==1 ){
					uni.switchTab({
						url:url
					})
				}else{
					uni.navigateTo({
						url:url
					})
				}
			},
			getGoodsInfo(){
				shop.getGoodsInfo({
					type:this.type,
					goodsId:this.goodsId,
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						this.goodsInfo = res.data
					}
				})
			},
			link(){
				shop.getlink({
					type:this.type,
					goodsId:this.goodsId,
				}).then(res => {
					if (res.code == 1) {
						// #ifdef H5
						window.location.href = res.data.url
						// wind.href = url
						// #endif
						
						// #ifdef APP-PLUS
						plus.runtime.openURL(res.data.url, (err) => {
							if (err) {
								uni.showToast({
									title: "跳转失败，请检查链接",
									icon: "none"
								});
							}
						});
						// #endif
					}
				})
			},
			tel(){
				uni.showModal({
					title: '联系客服', // 对话框的标题
					content: '客服上班时间:上午9:00～晚上9:00', // 对话框的内容
					showCancel: true, // 是否显示取消按钮
					cancelText: '取消', // 取消按钮的文字
					cancelColor: '#000000', // 取消按钮的文字颜色
					confirmText: '确定', // 确定按钮的文字
					confirmColor: '#3CC51F', // 确定按钮的文字颜色
					success: function(res) { // 回调函数
						if (res.confirm) { // 用户点击了确定
							uni.makePhoneCall({
								phoneNumber: '4008390228'
							});
						} else if (res.cancel) { // 用户点击了取消
							console.log('用户点击取消');
						}
					},
					fail: function(err) { // 弹出框失败的回调
						console.log('弹出框失败：', err);
					},
					complete: function() { // 弹出框完成的回调
						console.log('弹出框完成');
					}
				});
			}
		},
	}
</script>

<style lang="scss" scoped>
.page{
	background-color: #f5f5f5;
	min-height: 100vh;
}
.goods-swiper{
	width: 750rpx;
	height: 750rpx;
	overflow: hidden;
}
.home1-img-box {
	width: 750rpx;
	height: 750rpx;
	display: flex;
	align-items: top;
	justify-content: center;
	overflow: hidden;
}
.home1-img {
		width: 750rpx;
	}
.home1-swiper >>> .wx-swiper-dots.wx-swiper-dots-horizontal {
	bottom: 55rpx;
	background-color: rgba(255, 255, 255, .3);
	border-radius: 6rpx;
}
.home1-swiper >>> .wx-swiper-dot {
	width: 28rpx;
	height: 6rpx;
	border-radius: 6rpx;
	background: none;
	margin-left: 0;
	margin-right: 0;
}
.home1-swiper >>> .wx-swiper-dot-active {
	background-color: #fff;
}
.footer{
	padding-top: 24rpx;
	padding-left: 24rpx;
	padding-right: 24rpx;
	padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
	background-color: #fff;
	display: flex;
	align-items: center;
	position: fixed;
	display: flex;
	justify-content: space-between;
	left: 0;
	bottom: 0;
	right: 0;
	z-index: 999;
}
.footer1 {
	display: flex;
	align-items: center;
	justify-content: center;
	margin-right: auto;
}
.footer-img {
	width: 41rpx;
	height: 41rpx;
}
.footer-name {
	font-size: 24rpx;
	color: #333;
	margin-top: 10rpx;
}
.row1{
	margin: 20rpx;background-color: #fff;border-radius: 20rpx;padding: 20rpx;
}
.price{
	display: flex;align-items: center;justify-content: space-between;
}
.money{
	display: flex;margin-top: 20rpx;
}
.money-item{
	display: flex;gap: 16rpx;
}
.money-left{
	background-color:#ff533d;color: #fff;font-size: 24rpx;padding: 4rpx 12rpx;border-radius: 4rpx;
}
.money-right{
	background-color: #371c00;color: #ddc87e;font-size: 24rpx;padding: 4rpx 12rpx;border-radius: 4rpx;
}
.content{
	margin: 20rpx;background-color: #fff;border-radius: 20rpx;padding: 20rpx;display: flex;flex-direction: column;
}
.content-img{
	width: 100%;
}
.title{
	border-left: 2rpx;font-size: 32rpx;margin-bottom: 20rpx;font-weight: bold;
}
.price-left{
	display: flex;align-items: center
}
.price-icon{
	font-size: 22rpx;color: red;
}
.market-price{
	font-size: 26rpx;color: #999;margin-left: 40rpx;
}
.sale-price{
	font-size: 42rpx;color: red;font-weight: bold;
}
.link{
	background-color: red;padding: 20rpx 40rpx;width: 400rpx;display: flex;align-items: center;text-align: center;justify-content: center;border-radius: 40rpx;
}
.link-title{
	color: #fff;font-size: 32rpx;font-weight: bold;position: relative;
}
.link-price{
	position: absolute;top: 0;right: 30rpx;background-color: #FFEC62;font-size: 20rpx;padding: 5rpx 10rpx;border-radius: 20rpx;color: #fb1c48
}
</style>
